﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Configuration;

namespace OpenExpressApp.Server.WPFHost
{
    /// <summary>
    /// Interaction logic for SelectDataBaseDialog.xaml
    /// </summary>
    public partial class SelectDataBaseDialog : Window
    {
        public SelectDataBaseDialog()
        {
            InitializeComponent();

            this.InitDataBases();
        }

        public string SelectedSettingsName
        {
            get
            {
                return Convert.ToString(LBSettings.SelectedItem);
            }
        }

        private void StackPanel_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = e.OriginalSource == BConfirm && 
                LBSettings.SelectedIndex >= 0;
            e.Handled = true;

            this.Close();
        }

        private void InitDataBases()
        {
            var connectionStrings = ConfigurationManager.ConnectionStrings
                .Cast<ConnectionStringSettings>()
                .Select(c => c.Name)
                .ToArray();
            LBSettings.ItemsSource = connectionStrings;
        }
    }
}
